<%@ Language=VBScript %>
<%Option Explicit%>

<!--#include file="../cons.asp"-->
<!--#include file="../../Common/Database.asp"-->

<body style="margin: 0px;">
<%
	response.CacheControl = "no-cache"
	Dim ChartFX1
	Dim Conn, RS, sSQL, oRSPG
	Dim aDatos
	Dim CfxArray
	Dim IdMateria, IdSedeCurso, IdAlumno, i
	
	IdMateria = request("IdMateria")
	IdSedeCurso = request("IdSedeCurso")
	IdAlumno = request("IdAlumno")
		
	Set ChartFX1 = Server.CreateObject("ChartFX.WebServer")
	Set CfxArray = CreateObject("CfxData.Array")

	Set Conn = Server.CreateObject("ADODB.Connection")
	Set RS = Server.CreateObject("ADODB.Recordset")
	Set oRSPG = Server.CreateObject("ADODB.Recordset")
	Conn.Open sConnectionString


	sSQL =	"select P.NroPeriodo, P.OrdenPeriodo, avg(NM.nota) as nota from NotasModalidad NM " & _
            "inner join Notas N on (N.IdNota = NM.IdNota "
            
		if trim(IdMateria) <> "TODAS" then
			sSQL = sSQL & "and N.IdMateria=" & IdMateria & ") "
		else
			sSQL = sSQL & ") "
		end if	
	
		sSQL = sSQL &	"inner join AlumnosCurso AC on (AC.IdAlumnoCurso = N.IdAlumnoCurso) " & _
		                "inner join Periodos P on (P.IdPeriodo = N.IdPeriodo) " & _
		                "inner join Alumnos A on (A.IdAlumno = AC.IdAlumno and A.IdAlumno = " & IdAlumno & ") " & _
						"where NM.Nota <> 0 " & _
						"group by P.NroPeriodo, P.OrdenPeriodo " & _
						"order by P.NroPeriodo, P.OrdenPeriodo asc"
	
	'response.write sSQL
	'response.end
	Set RS = Conn.Execute(sSQL)
	aDatos = RS.GetRows()
	
	Dim nValues()
	Dim nLegend()

	Redim nValues(ubound(aDatos,2)+1)
	Redim nLegend(ubound(aDatos,2)+1)
		
	for i=0 to ubound(aDatos,2)
		nValues(i) = cdbl(aDatos(2,i))
		nLegend(i) = "T: " & aDatos(0,i) & " Q: " & aDatos(1,i)
		'nValues(i) = 3.2
		'nLegend(i) = "a"
		'response.write i & "<br>"
		'response.write "nValues: " & nValues(i) & "<br>"
		'response.write "nLegend: " & nLegend(i) & "<br>"
	next
	
	'Redim nValues(4)
	'Redim nLegend(4)
	'nValues(0) = 7
	'nValues(1) = 7
	'nValues(2) = 6
	'nValues(3) = 6
	
	'nLegend(0) = "a"
	'nLegend(1) = "b"
	'nLegend(2) = "c"
	'nLegend(3) = "e"
	
	CfxArray.AddArray nValues
	CfxArray.AddArray nLegend
	'response.End
	
		
	ChartFX1.GetExternalData CfxArray
	
	'ChartFX1.Title(2) = "HOLA"
	
	ChartFX1.Chart3D = false
	ChartFX1.Gallery = 1
	ChartFX1.PointLabelAlign = 6
	ChartFX1.PointLabels = true
	ChartFX1.BorderStyle=0
	ChartFX1.RGBBK = rgb(252,252,228)
	ChartFX1.LeftGap = 50
	ChartFX1.RightGap = 50
	ChartFX1.topGap = 30
	ChartFX1.bottomGap = 10
	ChartFX1.LegendBox=false
	ChartFX1.LegendBoxObj.Docked = 258
	ChartFX1.LegendBoxObj.Font.Bold = true
	ChartFX1.LegendBoxObj.BkColor = &HFFFFFF&
	'ChartFX1.DataEditorObj.BkColor = &HFFFFFF&
	'ChartFX1.MultipleColors = true
	ChartFX1.OpenDataEx 3,3,0
	ChartFX1.Color(0) = rgb(0,0,255)
	ChartFX1.Color(1) = rgb(0,255,0)
	ChartFX1.Color(2) = rgb(255,0,0)
	ChartFX1.CloseData 3
	
	ChartFX1.Axis(0).Max=10
	ChartFX1.Axis(0).Min=0
	
	ChartFX1.Axis(2).LabelAngle=90
	
	ChartFX1.ImgWidth = 600
	ChartFX1.ImgHeight = 400

	'ChartFX1.OpenDataEx 1, 1, 0
		'ChartFX1.Color(0)= rgb(252,252,228)
	'	ChartFX1.Color(1)= rgb(252,252,228)
		'ChartFX1.Color(2)= rgb(252,252,228)
	'ChartFX1.CloseData 1

	response.Write ChartFX1.GetHtmlTag("100%","100%","Png")
	
	
Public function GetNotaDecCol(nota, idec)
	Dim sNota, iNotaConvert
	
	iNotaConvert = FormatNumber(nota, idec)
	
	sNota = "<font color="""
	if iNotaConvert >= 0 and iNotaConvert < 4 then
		sNota = sNota & "red"
	end if
	
	if iNotaConvert >= 4 and iNotaConvert < 6 then
		sNota = sNota & "green"
	end if
	
	if iNotaConvert >= 6 and iNotaConvert <= 10 then
		sNota = sNota & "blue"
	end if
	
	sNota = sNota & """>" & iNotaConvert & "</font>"
	GetNotaDecCol = sNota
End function
%>
</body>